{extend name="common/common" /} {block name="style"}
<style type="text/css">
	.container-fluid .btn {
		float: right;
		margin-left: 10px;
	}
	.btn.btn-sm {
		margin: 0;
	}
	.layui-input.layui-unselect {
		width: 182px;
	}
	.layui-input-block {
		margin-left: 80px;
	}
	.layui-input.layui-unselect{
		width: 100px;
	}
	#cusTable tr{
		cursor: pointer;
	}
	.fixed-table-container thead th .sortable{
		padding-right: 0;
	}
	.layui-layer-btn.layui-layer-btn- a.layui-layer-btnAgree{
		color: #fff;
		background-color: #1ab394;
		border-color:#1ab394;
	}
	.layui-layer-btn.layui-layer-btn- a.layui-layer-btnDisagree{
		color: #fff;
		background-color: #ed5565;
		border-color:#ed5565;
	}
	.btn-bar{
		position: absolute;
	}
	.btn-bar .btn{
		margin-top: 10px;
	}
</style>
{/block} {block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>财务流水列表</h5>
		</div>
		<div class="ibox-content">
			<!-- start of search -->
			<form class="layui-form" action="" id="seaForm">
				<div class="layui-form-item">
					<div class="layui-input-inline">
						<input type="text" name="seaSn" id="seaSn" placeholder="订单单号/流水单号" class="layui-input">
					</div>
					<div class="layui-input-inline" style="width:100px;">
						<input type="text" name="seaName" id="seaName" placeholder="姓名" class="layui-input">
					</div>
					<div class="layui-input-inline" style="width:100px;">
						<select name="seaName" id="seaSchool" lay-filter="getMajor" >
							<option value="" selected>学校</option>
							{volist name="$CanseeSchool" id="v"}
							<option value="{$v.id}">{$v.name}</option>
							{/volist}
						</select>
					</div>
					<div class="layui-input-inline" style="width:100px;">
						<select name="seaMajor" id="seaMajor">
							<option value="" selected>专业</option>
						</select>
					</div>
					<div class="layui-input-inline" style="width:100px;">
						<select name="seaGrade" id="seaGrade">
							<option value="" selected>层次</option>
							{volist name="$grade_opt" id="v"}
							<option value="{$v.id}">{$v.name}</option>
							{/volist}
						</select>
					</div>
					<div class="layui-input-inline" style="width:100px;">
						<input type="text" name="seaBatch_member" id="seaBatch_member" placeholder="批次" class="layui-input">
					</div>
					<div class="layui-input-inline" style="width:100px;">
						<input type="text" name="seaAsker" id="seaAsker" placeholder="咨询师" class="layui-input">
					</div>
					<div class="layui-input-inline" style="width:100px;">
						<input type="text" name="seaAsk_D" id="seaAsk_D" placeholder="咨询师部门" readonly class="layui-input">
						<input type="hidden" name="seaAsk_D_id" id="seaAsk_D_id">
					</div>

					<div class="layui-input-inline" style="width:100px;">
						<select name="seaFee" id="seaFee">
							<option value="" selected>费用</option>
							<option value="tuition">学费</option>
							<option value="registration">报名费</option>
							<option value="material_cost">资料费</option>
							<option value="	photo_collection">照片采集费</option>
						</select>
					</div>
					<div class="layui-input-inline" style="width: 100px;">
						<select name="seaSource" id="seaSource">
							<option value="" selected>来源</option>
							<option value="0">学员</option>
							<option value="1">报销</option>
							<option value="2">罚款</option>
							<option value="3">退款</option>
							<option value="4">其他</option>
						</select>
					</div>
					<div class="layui-input-inline" style="width: 100px;">
						<select name="seaStatus" id="seaStatus">
							<option value="" selected>状态</option>
							<option value="0">未支付</option>
							<option value="1">已支付</option>
							<option value="2">已逾期</option>
							<option value="3">已拒绝</option>
							<option value="4">已同意</option>
						</select>
					</div>

					<div class="layui-inline">
						<input type="text" class="layui-input" id="seaTime" name="seaTime" placeholder="时间范围">
					</div>
					<div class="layui-inline">
						<button type="button" id="search" class="btn btn-info" style="margin-top: 2px;">查询</button>
					</div>
				</div>
			</form>
			<!-- end of search -->
			<div class="btn-bar">
				{if authCheck('finance/delaccount')}
				<a class="btn btn-danger getIDs" href="javascript:delAccount();" data-param=''>删除流水</a>
				{/if}
				{if authCheck('finance/addexpense')}
				<a class="btn btn-primary" href="{:url('finance/addExpense')}">添加报销单</a>
				{/if}
				{if authCheck('finance/addticket')}
				<a class="btn btn-warning" href="{:url('finance/addTicket')}">添加罚款单</a>
				{/if}
			</div>
			<table id="cusTable">
				<thead>
					<th>checkbox</th>
					<th class="text-center" data-width="100px" data-field="id" data-sortable="true" data-sort-name="id">ID <i class='fa fa-sort' id="fa-id"></i></th>
					<th class="text-center" data-width="150px" data-field="order_sn" data-visible="false">订单单号</th>
					<th class="text-center" data-width="150px" data-field="account_sn">流水单号</th>
					<th class="text-center" data-width="100px" data-field="source_name">来源</th>
					<th class="text-center" data-width="100px" data-field="name">学员/报销人</th>
					<th class="text-center" data-width="200px" data-field="from_s">学校/部门</th>
					<th class="text-center" data-width="100px" data-field="grade">层次</th>
					<th class="text-center" data-width="200px" data-field="from_m">专业</th>
					<th class="text-center" data-width="100px" data-field="batch_member">批次</th>
					<th class="text-center" data-width="100px" data-field="first">咨询师1</th>
					<th class="text-center" data-width="100px" data-field="first_depart" data-visible="false">咨询师1部门</th>
					<th class="text-center" data-width="100px" data-field="second" data-visible="false">咨询师2</th>
					<th class="text-center" data-width="100px" data-field="second_depart" data-visible="false">咨询师2部门</th>
					<th class="text-center" data-width="100px" data-field="tuition" data-visible="false">学费</th>
					<th class="text-center" data-width="100px" data-field="registration" data-visible="false">报名费</th>
					<th class="text-center" data-width="100px" data-field="material_cost" data-visible="false">资料费</th>
					<th class="text-center" data-width="100px" data-field="photo_collection" data-visible="false">照片采集费</th>
					<th class="text-center" data-width="100px" data-field="total_amount_name">总金额</th>
					<th class="text-center" data-width="100px" data-field="agent_name">经办人</th>
					<th class="text-center" data-width="120px" data-field="finish_time" data-sortable="true" data-sort-name="finish_time">到期时间 <i class='fa fa-sort' id="fa-finish_time"></i></th>
					<th class="text-center" data-width="120px" data-field="receivables_time">收款时间</th>
					<th class="text-center" data-width="100px" data-field="status_name">状态</th>
					{if authCheck('finance/receivables')}
					<th class="text-center" data-width="100px" data-field="operate">操作</th>
					{/if}

					{if authCheck('finance/authrefund')}
					<th class="text-center" data-width="100px" data-field="auth">授权退款</th>
					{/if}
					<th class="text-center" data-width="100px" data-field="print">打印收据</th>
				</thead>
			</table>
		</div>
	</div>
</div>
<div class="TreeBox" style="display:none;padding:15px;">
	<ul id="tree"></ul>
</div>
<div class="remarksBox" style="display:none;padding:15px;"></div>
<input type="hidden" id="openType" value="{$Think.get.type|default=0}">
{/block} {block name="script"}
<script type="text/javascript">
	var IDs = '';

	function initTable() {
		//先销毁表格
		$('#cusTable').bootstrapTable('destroy');
		//初始化表格,动态从服务器加载数据
		$("#cusTable").bootstrapTable({
			method: "get", //使用get请求到服务器获取数据
			url: "./accList", //获取数据的地址
			striped: true, //表格显示条纹
			pagination: true, //启动分页
			pageSize: 25, //每页显示的记录数
			pageNumber: 1, //当前第几页
			pageList: [25,50,100,150,200,500], //记录数可选列表
			sidePagination: "server", //表示服务端请求
			paginationFirstText: "首页",
			paginationPreText: "上一页",
			paginationNextText: "下一页",
			paginationLastText: "尾页",
			queryParamsType: "undefined",
			resizable:true,
			silentSort:false,//分页记住排序
			sortName:'id',
			sortOrder:'desc',
			showColumns:true,
			columns: [{
				checkbox: true,
				formatter: function(value, row, index) {
					if (row.state == true) {
						return {
							checked: value, //设置选中
						};
					}
					return value;
				},
			}],
			queryParams: function queryParams(params) { //设置查询参数
				var param = {
					pageNumber: params.pageNumber,
					pageSize: params.pageSize,
					seaSn: $("#seaSn").val(),
					seaName: $("#seaName").val(),
					seaSource: $("#seaSource").val(),
					seaStatus: $("#seaStatus").val(),
					seaTime: $("#seaTime").val(),
					seaBatch_member: $("#seaBatch_member").val(),
					seaSchool: $("#seaSchool").val(),
					seaMajor: $("#seaMajor").val(),
					seaGrade: $("#seaGrade").val(),
					seaAsker: $("#seaAsker").val(),
					seaAsk_D: $("#seaAsk_D_id").val(),
					seaFee: $("#seaFee").val(),
					sortName:this.sortName,
					sortOrder:this.sortOrder,
				};
				return param;
			},
			onLoadSuccess: function(res) { //加载成功时执行
				if (111 == res.code) {
					window.location.reload();
				}
				layer.msg("加载成功", {time: 1000});
			},
			onLoadError: function() { //加载失败时执行
				layer.msg("加载数据失败");
			},
			onDblClickRow: function(row) {
				$(".remarksBox").html(row.remarks);
				var rmBox = layer.open({
					type:1,
					title:"备注信息",
					area:["300px","200px"],
					content:$(".remarksBox")
				});
			},
			onSort:function(name,order){ //切换排序图标
				var idName = 'fa-' + name;
				var oSort = document.getElementById(idName);
				var oFaId = document.getElementById('fa-id');
				var oFaTm = document.getElementById('fa-finish_time');
				oFaId.className = 'fa fa-sort';
				oFaTm.className = 'fa fa-sort';
				order == 'asc'?oSort.className = 'fa fa-sort-up':oSort.className = 'fa fa-sort-down';
			}
		});
	}

	$(function() {
		var openType = $("#openType").val();//0.正常打开,1.统计跳转
		if(openType == '1'){
			$("#seaStatus").val('{$Think.get.seaStatus}');
			$("#seaTime").val('{$Think.get.seaTime}');
			$("#search").click();
		}
		//调用函数，初始化表格
		initTable();
		getTree();
		layui.use(['form','laydate'], function() {
			var form = layui.form,laydate = layui.laydate;
			laydate.render({elem: '#seaTime',range: true});
			form.on('select(getMajor)',function(data){
				$.post('{:url("Finance/getMajorByPid")}',{pid:data.value},function(res){
					var op = '<option value="" selected>专业</option>';
					for(var i=0;i<res.data.length;i++){
						op += '<option value="'+res.data[i].id+'">'+res.data[i].name+'</option>';
					}
					$("#seaMajor").html(op);
					form.render();
				});
			});
		});
		//当点击查询按钮的时候执行
		$("#search").bind("click", initTable);

		$('.getIDs').on('click', function() {
			var checkedOn = $('#cusTable').bootstrapTable('getSelections');
			var IDs = '';
			for (var i = 0; i < checkedOn.length; i++) {
				if (i == 0) {
					IDs = checkedOn[0].id;
				} else {
					IDs += ',' + checkedOn[i].id;
				}
			}
			$('.getIDs').attr('data-param', IDs);
		});
		$('.cancel').on('click', function() {
			layer.closeAll();
		});

		$('#seaAsk_D').on('click',function(){
			layer.open({
				type:1,
				title:'请选择部门',
				area:['325px','350px'],
				content:$('.TreeBox')
			});
		});
	});

	function delAccount(ids = null) {
		if (ids == null) {
			ids = $('.getIDs').attr('data-param');
		}
		if (ids != '') {
			layer.confirm('确认删除这些数据?', {icon: 3,title: '提示'}, function(index) {
				$.post('./delAccount', {ids: ids}, function(res) {
					if (res.code == 1) {
						layer.alert(res.msg, {title: '友情提示',icon: 1,closeBtn: 0}, initTable);
					} else {
						layer.msg(res.msg, {anim: 6});
					}
				});
			});
		} else {
			layer.msg("请选择数据", {anim: 6});
		}
	}

	function resetCheckBox() {
		var aCheckBox = $('.schools');
		for (var j = 0; j < aCheckBox.length; j++) {
			aCheckBox[j].checked = false;
		}
		layui.use(['form'], function() {
			var form = layui.form;
			form.render();
		});
	}
	// 收款
	function receivables(id){
		layer.confirm('确认收款?', {icon: 3,title: '提示'}, function(index) {
			$.post("./receivables",{id:id},function(res){
				if (res.code == 1) {
					layer.alert(res.msg, {title: '友情提示',icon: 1,closeBtn: 0}, initTable);
				} else {
					layer.msg(res.msg, {anim: 6});
				}
			});
		});
	}
	//授权退款
	function authRefund(id){
		var authRefundBox = layer.confirm('同意/拒绝 该退款？', {
			icon: 3,
			title: '提示',
		  	btn: ['同意', '拒绝', '取消'],
			success:function(layer){
				layer[0].childNodes[3].childNodes[0].attributes[0].value='layui-layer-btnAgree';
				layer[0].childNodes[3].childNodes[1].attributes[0].value='layui-layer-btnDisagree';
			},
		  	btn1: function(){
				layer.confirm('确认同意?', {icon: 3,title: '提示'}, function() {
					authAccount(id,1);
				});
			},
			btn2: function(){
			    layer.confirm('确认拒绝?', {icon: 3,title: '提示'}, function() {
					authAccount(id,0);
				});
			}
		});
	}

	function authAccount(acc_id,agree){
		$.post('./authRefund',{acc_id:acc_id,agree:agree},function(res){
			if (res.code == 1) {
				layer.closeAll();
				layer.alert(res.msg, {title: '友情提示',icon: 1,closeBtn: 0}, initTable);
			} else {
				layer.msg(res.msg, {anim: 6});
			}
		})
	}

	function AccPrint(id){
		layer.open({
			type:2,
			title:"打印收据",
			area:['800px','500px'],
			content:"{:url('finance/AccPrint')}?acc_id="+id
		})
	}

	function getTree(){
	    layui.use(['tree', 'layer'], function(){
	        var layer = layui.layer;

	        $.getJSON("{:url('department/index')}", function(res){
	            if(111 == res.code){
	                window.location.reload();
	            }
	            layui.tree({
	                elem: '#tree'
	                ,nodes: res.data
	                ,click: function(node){
						$('#seaAsk_D').val(node.name);
						$('#seaAsk_D_id').val(node.id);
						layer.closeAll();
	                    nowNode = node;
	                }
	            });
	        });
	    });
	}
</script>
{/block}
